package com.ruoyi.activiti.domain;

import cn.hutool.core.collection.CollectionUtil;
import com.ruoyi.common.core.web.domain.BaseEntity;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import java.util.*;

/**
 * @author scihi
 */
@Data
@ApiModel("任务对象")
public class TaskVo extends BaseEntity {

    private String taskId;

    @ApiModelProperty("任务动作，用于操作任务。COMPLETE：完成、BACK：回退、REJECT：驳回、DELEGATE：转办、JUMP：跳转、DELETE：删除")
    private String action;

    @ApiModelProperty("处理方式中文")
    private String actionName;

    private String taskName;

    @ApiModelProperty("流程实例id")
    private String instanceId;

    private String instanceName;//流程实例名，可以认为是流程实例标题

    @ApiModelProperty("流程定义id")
    private String definitionId;

    private String definitionName;//流程定义名

    @ApiModelProperty("激活状态，1：已激活，2：已挂起")
    private String suspendState;

    private String suspendStateName;

    private Date createTime;

    private String creatorName;

    private String userId;//任务的所属人

    private Integer pageNum;

    private Integer pageSize;

    private Integer offset;

    @ApiModelProperty("处理人")
    private String assignee;

    @ApiModelProperty("任务到达时间开始")
    private Date startTime;

    @ApiModelProperty("任务到达时间结束")
    private Date endTime;

    /**
     * 类型 todo 待办 done 已办
     */
    private String type;

    private Set<TaskAssignee> taskAssignees;

    public TaskVo addAssignee(TaskAssignee taskAssignee){
        if(CollectionUtil.isEmpty(this.taskAssignees)){
            this.taskAssignees = new HashSet<>();
        }
        this.taskAssignees.add(taskAssignee);
        return this;
    }

    @ApiModelProperty("审批意见")
    private String comment;

    private String delegateToUser;

    @ApiModelProperty("要跳转的目标节点id")
    private String targetActivityId;

    private String state;

    @ApiModelProperty("当前节点id")
    private String taskDefinitionKey;

    @ApiModelProperty("流程的变量")
    private Map<String, String> variables;

    public void addVariable(String key, String val) {
        if(CollectionUtil.isEmpty(this.variables)){
            this.variables = new HashMap<>();
        }
        this.variables.put(key, val);
    }
}
